#include <bits/stdc++.h>
#define int long long
#define INT_MAX LLONG_MAX
#define INT_MIN LLONG_MIN
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int32_t main () {
fastio();
int t, n, rem;
t = 1;
while (t--) {
cin >> n;
vector<int> arr(n), cnt(3, 0);
for (int i = 0; i < n; i++) {
cin >> arr[i];
cnt[arr[i]%3]++;
}
if (cnt[0] <= n/2) {
cout << 0 << '\n';
rem = n/2 - cnt[0];
for (int i = 0; i < n; i++) {
if (arr[i]%3 == 0) {
cout << 0;
}
else {
if (rem) {
cout << 0;
rem--;
}
else {
cout << 1;
}
}
}
cout << '\n';
}
else if (cnt[1]+cnt[2] <= n/2) {
cout << 2 << '\n';
rem = n/2 - (cnt[1]+cnt[2]);
for (int i = 0; i < n; i++) {
if (arr[i]%3 == 1 || arr[i]%3 == 2) {
cout << 0;
}
else {
if (rem) {
cout << 0;
rem--;
}
else {
cout << 1;
}
}
}
cout << '\n';
}
else {
cout << -1 << '\n';
}
}
return 0;
}
3. Longest Substring Without Repeating Characters | 1312. Minimum Insertion Steps to Make a String Palindrome |
1092. Shortest Common Supersequence | 1044. Longest Duplicate Substring |
1032. Stream of Characters | 987. Vertical Order Traversal of a Binary Tree |
952. Largest Component Size by Common Factor | 212. Word Search II |
174. Dungeon Game | 127. Word Ladder |
123. Best Time to Buy and Sell Stock III | 85. Maximal Rectangle |
84. Largest Rectangle in Histogram | 60. Permutation Sequence |
42. Trapping Rain Water | 32. Longest Valid Parentheses |
Cutting a material | Bubble Sort |
Number of triangles | AND path in a binary tree |
Factorial equations | Removal of vertices |
Happy segments | Cyclic shifts |
Zoos | Build a graph |
Almost correct bracket sequence | Count of integers |
Differences of the permutations | Doctor's Secret |